package com.Data;

import java.io.File;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.PersistenceException;
import org.simpleframework.xml.core.Persister;

import android.content.res.Resources.NotFoundException;

import com.Domain.Channel;
import com.EdificacioAR.DebugLog;

public class XMLReader {

	private static final String TAG = "XMLReader";
	
	public static Channel readXML(File xmlFile) {
		
		DebugLog.LOGD(TAG + " - Starting to read XML File: " + xmlFile.getName());
		Serializer serial = new Persister();
		
		try {
			
			Channel channel = serial.read(Channel.class, xmlFile, false);
			DebugLog.LOGD(TAG + " - " + channel.toString());
			return channel;
			
		} catch (NotFoundException e) {
			DebugLog.LOGE(TAG + " - XML File not found");
		} catch (PersistenceException e) {
			DebugLog.LOGE(TAG + " - Unserializing persistence Exception");
			e.getMessage();
			e.printStackTrace();
		} catch (Exception e) {
			DebugLog.LOGE(TAG + " - Error parsing the channel XML File");
			e.printStackTrace();
		}
		
		
		return null;
		
	}
}
